package com.wude.guild.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.wude.bean.TrafficListBean;
import com.wude.guild.face.TrafficAdapterFace;
import com.wude.guild.holder.TrafficHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述：流量列表Adapter
 * 时间: 2017-09-05 14:47
 */
public class ListTrafficAdapter extends BaseAdapter {
    private Activity activity;
    private List<TrafficListBean.DataBean> list = new ArrayList<>();
    private TrafficAdapterFace face;

    public ListTrafficAdapter(Activity activity, TrafficAdapterFace face) {
        this.activity = activity;
        this.face = face;
    }

    public List<TrafficListBean.DataBean> getListBeen() {
        return list;
    }

    public void setListBeen(List<TrafficListBean.DataBean> listBeen) {
        this.list = listBeen;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TrafficHolder holder = null;
        if (holder == null) {
            holder = new TrafficHolder(face);
        } else {
            holder = (TrafficHolder) convertView.getTag();
        }

        list.get(0).setCount(list.size());

        if (list.size() == 1)
            list.get(position).setHasMore(false);
        else
            list.get(position).setHasMore(true);

        if (position == list.size() - 1)
            list.get(position).setHasMore(false);


        holder.setData(list.get(position), position, activity);
        return holder.getContentView();
    }
}
